15 openstreetmap
Downloading OpenStreetMap data with a single line of code
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# !pip install geopandas osmnx leafmap
# !pip install geopandas osmnx leafmap
In [2]:
Copied!
import leafmap
import leafmap
Add OSM data of place(s) by name or ID to the map. Note that the leafmap custom layer control does not support GeoJSON, we need to use the ipyleaflet built-in layer control.
In [3]:
Copied!
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_geocode("New York City", layer_name='NYC')
m
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_geocode("New York City", layer_name='NYC')
m
Out[3]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [4]:
Copied!
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_geocode("Chicago, Illinois", layer_name='Chicago, IL')
m
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_geocode("Chicago, Illinois", layer_name='Chicago, IL')
m
Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Add OSM entities within boundaries of geocodable place(s) to the map.
In [5]:
Copied!
m = leafmap.Map(toolbar_control=False, layers_control=True)
place = "Bunker Hill, Los Angeles, California"
tags = {"building": True}
m.add_osm_from_place(place, tags, layer_name="Los Angeles, CA")
m
m = leafmap.Map(toolbar_control=False, layers_control=True)
place = "Bunker Hill, Los Angeles, California"
tags = {"building": True}
m.add_osm_from_place(place, tags, layer_name="Los Angeles, CA")
m
2022-01-03 14:48:35 Configured OSMnx 1.1.2 2022-01-03 14:48:35 HTTP response caching is on 2022-01-03 14:48:35 Retrieved response from cache file "cache/8d8366ad6b96fa854a9d6d038c022b8bdcdb6fe6.json" 2022-01-03 14:48:35 Created GeoDataFrame with 1 rows from 1 queries 2022-01-03 14:48:35 Constructed place geometry polygon(s) to query API 2022-01-03 14:48:35 Projected GeoDataFrame to +proj=utm +zone=11 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +type=crs 2022-01-03 14:48:35 Projected GeoDataFrame to epsg:4326 2022-01-03 14:48:35 Requesting data within polygon from API in 1 request(s) 2022-01-03 14:48:35 Retrieved response from cache file "cache/95fea0c13cd89a78cbaa52ae4b13a8c9ebd9eb21.json" 2022-01-03 14:48:35 Got all geometries data within polygon from API in 1 request(s) 2022-01-03 14:48:35 Converting 1436 elements in JSON responses to geometries 2022-01-03 14:48:35 77 geometries created in the dict 2022-01-03 14:48:35 13 untagged geometries removed 2022-01-03 14:48:35 Created r-tree spatial index for 64 geometries 2022-01-03 14:48:35 Identified 64 geometries inside polygon 2022-01-03 14:48:35 0 geometries removed by the polygon filter 2022-01-03 14:48:35 8 geometries removed by the tag filter 2022-01-03 14:48:35 56 geometries in the final GeoDataFrame
Out[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Show OSM feature tags.
In [6]:
Copied!
# leafmap.osm_tags_list()
# leafmap.osm_tags_list()
Add OSM entities within some distance N, S, E, W of address to the map.
In [7]:
Copied!
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_address(
address="New York City",
tags={"amenity": "bar"},
dist=1500,
layer_name="NYC bars")
m
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_address(
address="New York City",
tags={"amenity": "bar"},
dist=1500,
layer_name="NYC bars")
m
2022-01-03 14:48:35 Pausing 1 seconds before making HTTP GET request 2022-01-03 14:48:36 Get https://nominatim.openstreetmap.org/search?format=json&limit=1&dedupe=0&q=New+York+City with timeout=180 2022-01-03 14:48:36 Resolved nominatim.openstreetmap.org to 140.211.167.100 2022-01-03 14:48:36 Downloaded 0.5kB from nominatim.openstreetmap.org 2022-01-03 14:48:36 Saved response to cache file "cache/78258c318356c20c380e1fed844176f90c053cf7.json" 2022-01-03 14:48:36 Geocoded "New York City" to (40.7127281, -74.0060152) 2022-01-03 14:48:36 Created bbox 1500 m from (40.7127281, -74.0060152): 40.72621790503239,40.69923829496761,-73.98821837587228,-74.02381202412771 2022-01-03 14:48:36 Projected GeoDataFrame to +proj=utm +zone=18 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +type=crs 2022-01-03 14:48:36 Projected GeoDataFrame to epsg:4326 2022-01-03 14:48:36 Requesting data within polygon from API in 1 request(s) 2022-01-03 14:48:36 Resolved overpass-api.de to 178.63.48.217 2022-01-03 14:48:37 Pausing 0 seconds before making HTTP POST request 2022-01-03 14:48:37 Post https://overpass-api.de/api/interpreter?data=%5Bout%3Ajson%5D%5Btimeout%3A180%5D%3B%28%28node%5B%27amenity%27%3D%27bar%27%5D%28poly%3A%2740.699238+-74.023812+40.699238+-73.988218+40.726218+-73.988218+40.726218+-74.023812+40.699238+-74.023812%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28way%5B%27amenity%27%3D%27bar%27%5D%28poly%3A%2740.699238+-74.023812+40.699238+-73.988218+40.726218+-73.988218+40.726218+-74.023812+40.699238+-74.023812%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28relation%5B%27amenity%27%3D%27bar%27%5D%28poly%3A%2740.699238+-74.023812+40.699238+-73.988218+40.726218+-73.988218+40.726218+-74.023812+40.699238+-74.023812%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%29%3Bout%3B with timeout=180 2022-01-03 14:48:37 Resolved overpass-api.de to 178.63.48.217 2022-01-03 14:48:39 Downloaded 37.2kB from overpass-api.de 2022-01-03 14:48:39 Saved response to cache file "cache/7d10c2e8d50f39407dda671d56290ea2808b3d4a.json" 2022-01-03 14:48:39 Got all geometries data within polygon from API in 1 request(s) 2022-01-03 14:48:39 Converting 107 elements in JSON responses to geometries 2022-01-03 14:48:39 98 geometries created in the dict 2022-01-03 14:48:39 0 untagged geometries removed 2022-01-03 14:48:39 Created r-tree spatial index for 98 geometries 2022-01-03 14:48:39 Identified 98 geometries inside polygon 2022-01-03 14:48:39 0 geometries removed by the polygon filter 2022-01-03 14:48:39 0 geometries removed by the tag filter 2022-01-03 14:48:39 98 geometries in the final GeoDataFrame
Out[7]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [8]:
Copied!
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_address(
address="New York City",
tags={
"landuse": ["retail", "commercial"],
"building": True
},
dist=1000, layer_name="NYC buildings")
m
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_address(
address="New York City",
tags={
"landuse": ["retail", "commercial"],
"building": True
},
dist=1000, layer_name="NYC buildings")
m
2022-01-03 14:48:39 Retrieved response from cache file "cache/78258c318356c20c380e1fed844176f90c053cf7.json" 2022-01-03 14:48:39 Geocoded "New York City" to (40.7127281, -74.0060152) 2022-01-03 14:48:39 Created bbox 1000 m from (40.7127281, -74.0060152): 40.721721303354926,40.703734896645074,-73.99415065058152,-74.01787974941847 2022-01-03 14:48:39 Projected GeoDataFrame to +proj=utm +zone=18 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +type=crs 2022-01-03 14:48:39 Projected GeoDataFrame to epsg:4326 2022-01-03 14:48:39 Requesting data within polygon from API in 1 request(s) 2022-01-03 14:48:39 Resolved overpass-api.de to 178.63.48.217 2022-01-03 14:48:40 Pausing 0 seconds before making HTTP POST request 2022-01-03 14:48:40 Post https://overpass-api.de/api/interpreter?data=%5Bout%3Ajson%5D%5Btimeout%3A180%5D%3B%28%28node%5B%27landuse%27%3D%27retail%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28way%5B%27landuse%27%3D%27retail%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28relation%5B%27landuse%27%3D%27retail%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28node%5B%27landuse%27%3D%27commercial%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28way%5B%27landuse%27%3D%27commercial%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28relation%5B%27landuse%27%3D%27commercial%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28node%5B%27building%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28way%5B%27building%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%28relation%5B%27building%27%5D%28poly%3A%2740.703735+-74.017880+40.703735+-73.994151+40.721721+-73.994151+40.721721+-74.017880+40.703735+-74.017880%27%29%3B%28._%3B%3E%3B%29%3B%29%3B%29%3Bout%3B with timeout=180 2022-01-03 14:48:40 Resolved overpass-api.de to 178.63.48.217 2022-01-03 14:48:50 Downloaded 2,725.2kB from overpass-api.de 2022-01-03 14:48:50 Saved response to cache file "cache/2c876f231fa35ebe028236a3fb06b51de7794ae0.json" 2022-01-03 14:48:50 Got all geometries data within polygon from API in 1 request(s) 2022-01-03 14:48:50 Converting 20990 elements in JSON responses to geometries 2022-01-03 14:48:50 2958 geometries created in the dict 2022-01-03 14:48:50 74 untagged geometries removed 2022-01-03 14:48:50 Created r-tree spatial index for 2884 geometries 2022-01-03 14:48:50 Identified 2877 geometries inside polygon 2022-01-03 14:48:50 7 geometries removed by the polygon filter 2022-01-03 14:48:50 133 geometries removed by the tag filter 2022-01-03 14:48:50 2751 geometries in the final GeoDataFrame
Out[8]:
Make this Notebook Trusted to load map: File -> Trust Notebook